﻿using System;
using Glue;
using Glue.Internals.Verification;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.RelationsVerificationTests
{
    public class When_ignoring_a_property_and_relation_exists
    {
        private readonly RelationsVerification<DomainPerson, GuiPerson> relationsVerification;
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public class DomainPerson
        {
            public String FirstName { get; set; }
            public String LastName { get; set; }
        }

        public class GuiPerson
        {
            public String FirstName { get; set; }
            public String LastName { get; set; }
        }

        public When_ignoring_a_property_and_relation_exists()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            relationsVerification = new RelationsVerification<DomainPerson, GuiPerson>(mapping, new ObjectMemberFactoryBuilder().Build());
        }

        [Fact]
        public void Should_throw_exception_if_a_relation_already_exist_with_that_property()
        {
            mapping.Relate(domain => domain.FirstName, gui => gui.FirstName);
            Assert.Throws(typeof(GlueException), () => mapping.IgnoreTowards<DomainPerson>(x => x.FirstName));
        }

        [Fact]
        public void Should_throw_exception_if_a_relation_already_exist_with_that_property_with_right_direction()
        {
            mapping.RelateTowardsLeft(domain => domain.FirstName, gui => gui.FirstName);
            Assert.Throws(typeof(GlueException), () => mapping.IgnoreTowards<DomainPerson>(x => x.FirstName));
        }

        [Fact]
        public void Should_work_if_a_relation_exist_with_that_property_that_is_in_other_direction()
        {
            mapping.RelateTowardsRight(domain => domain.FirstName, gui => gui.FirstName);
            mapping.IgnoreTowards<DomainPerson>(x => x.FirstName);
        }
    }
}
